package edu.hbsi.Exercise;


import java.util.ArrayList;
        import java.util.List;
        import java.util.Scanner;

public class KTVchooseArrayList {

    private List<String> songList = new ArrayList<>();

    public void addSong(String song) {
        songList.add(song);
    }

    public void moveToTop(String song) {
        if (songList.remove(song)) {
            songList.add(0, song);
        }
    }

    public void moveUp(String song) {
        int index = songList.indexOf(song);
        if (index > 0) {
            songList.remove(index);
            songList.add(index - 1, song);
        }
    }

    public void displaySongs() {
        System.out.println("当前歌曲列表：");
        for (int i = 0; i < songList.size(); i++) {
            System.out.println((i + 1) + ". " + songList.get(i));
        }
    }

    public static void main(String[] args) {
        KTVchooseArrayList system = new KTVchooseArrayList();
        system.addSong("稻香");
        system.addSong("夜曲");
        system.addSong("夜的第七章");
        system.addSong("听妈妈的话");
        system.addSong("龙卷风");

        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("-------------欢迎来到点歌系统点歌系统-------------");
            System.out.println("0.添加歌曲至列表");
            System.out.println("1.将歌曲置顶");
            System.out.println("2.将歌曲前移一位");
            System.out.println("3.退出");

            System.out.print("输入要执行的操作序号：");
            int option = scanner.nextInt();
            scanner.nextLine(); // 消耗换行符

            switch (option) {
                case 0:
                    System.out.print("输入要添加的歌曲名称：");
                    String song = scanner.nextLine();
                    system.addSong(song);
                    break;
                case 1:
                    System.out.print("输入要置顶的歌曲名称：");
                    song = scanner.nextLine();
                    system.moveToTop(song);
                    break;
                case 2:
                    System.out.print("输入要置前的歌曲名称：");
                    song = scanner.nextLine();
                    system.moveUp(song);
                    break;
                case 3:
                    System.out.println("您已退出系统");
                    system.displaySongs(); // 退出前显示歌曲列表
                    return;
                default:
                    System.out.println("无效的选项，请重新输入。");
            }

            system.displaySongs();
        }
    }
}

